<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <div class="Logout">
      <Logout>退出</Logout>

   <div class="image">
       <el-image :src="src2"></el-image>
       <!-- <el-image :src="src1"></el-image> -->
    </div>
     



    </div>
<!--    <el-button type="danger" @click="Logout">退出登录</el-button>-->
    <h1>添加家族成员信息</h1>
    
   
   

     <el-form-item label="人员ID" prop="id">
      <el-input style="width: 800px" v-model="ruleForm.id" placeholder="请输入人员ID" prefix-icon="el-icon-s-check" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>

     
   <el-form-item label="家谱ID" prop="id2">
      <el-input style="width: 800px" v-model="ruleForm.id2" placeholder="请输入家谱ID" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>


    <el-form-item label="姓名" prop="name">
      <el-input style="width: 800px" v-model="ruleForm.name" placeholder="请输入成员姓名" prefix-icon="el-icon-user-solid" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
   
    <el-form-item label="性别" prop="marry">
      <el-input style="width: 800px" v-model="ruleForm.marry" placeholder="请输入结婚日期" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>


   
<el-form-item label="出生时间" prop="birth">
      <el-input style="width: 800px" v-model="ruleForm.birth" placeholder="请输入出生日期" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
   
   

     <el-form-item label="死亡时间" prop="die">
      <el-input style="width: 800px" v-model="ruleForm.die" placeholder="请输入死亡时间" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>




 <el-form-item label="用户头像" prop="address">
      <el-input style="width: 800px" v-model="ruleForm.address" placeholder="请输入头像" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
    


<!-- <el-form-item label="配偶信息" prop="partner">
      <el-input style="width: 800px" v-model="ruleForm.partner" placeholder="请输入配偶信息" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>




<el-form-item label="子女信息" prop="child">
      <el-input style="width: 800px" v-model="ruleForm.child" placeholder="请输入子女信息" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->

<!-- 
<el-form-item label="生平事迹" prop="life">
      <el-input style="width: 800px" v-model="ruleForm.life" placeholder="请输入生平事迹" prefix-icon="el-icon-s-management" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item> -->




    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')" icon="el-icon-check">提交</el-button>
      <el-button type="danger" @click="resetForm('ruleForm')" icon="el-icon-refresh">重置</el-button>
    </el-form-item>
  </el-form>
  
 





</template>

<script>
import Logout from "./Logout";
export default {
  name: "AddFamily",
  components: {Logout},
  data () {
    return {

       src2:"https://pic4.zhimg.com/v2-14f1ce3eadbf6f2c70eca671463caca1_1440w.jpg?source=172ae18b",
      ruleForm: {
        id: '',
        name: '',
    //    level: '',
    //    type: '',
        address: '',
        die:'',
        marry:'',
        partner:'',
        life:'',
        birth:'',
        child:'',
        id2:'',
       
        
      },
      rules: {
        id:
          {required: true, message: '请输入成员编号', trigger: 'blur'},

        name:
          {required: true, message: '请输入成员姓名', trigger: 'blur'},

    //      level:
    //      {required: true, message: '请输入等级', trigger: 'change'},

    //    type:
    //     {required: true, message: '请输入特长', trigger: 'blur'},

        address:
          {required: true, message: '请输入用户头像地址', trigger: 'blur'},

          die:
          {required: true, message: '请输入死亡时间', trigger: 'blur'},

          marry:
          {required: true, message: '请输入结婚日期', trigger: 'blur'},

          partner:
          {required: true, message: '请输入配偶信息', trigger: 'blur'},

          life:
          {required: true, message: '请输入生平事迹', trigger: 'blur'},

          
          birth:
          {required: true, message: '请输入出生日期', trigger: 'blur'},

          child:
          {required: true, message: '请输入子女信息', trigger: 'blur'},

          id2:
          {required: true, message: '请输入家谱ID', trigger: 'blur'},

        

      },
    }
  },
  methods : {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(_this.ruleForm)
          //这个地方进行axios提交后台信息
          const params = {
            tno:_this.ruleForm.id,
            tname:_this.ruleForm.name,
       //     tlevel:_this.ruleForm.level,
       //     tcharacter:_this.ruleForm.type,
            taddress: _this.ruleForm.address,
            tdie:_this.ruleForm.die,
            tmarry:_this.ruleForm.marry,
            tpartner:_this.ruleForm.partner,
            tlife:_this.ruleForm.life,
            tbirth:_this.ruleForm.birth,
            tchild:_this.ruleForm.child,
            thonor:_this.ruleForm.id2,
           

          }
          console.log("tno:", params.tno, " tname:", params.tname, " tlevel:", params.tlever, " tc:", params.tcharacter)
          this.$axios.post(`/InsertFamily`,params).then((res) => {   // 请求后端  给后端传参数  在执行then（res）之前，先向后端请求，前端一直等待后端返回的状态码
            console.log(res);   
           
           if (res.data.msg=="插入家族成员成功") { //如果返回信息，则插入成功
              alert("插入家族成员成功")
            } else {
              alert("插入家族成员失败")
            }
          });
        
        }
      });
    },



    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    Logout() {
      var _this = this;
      _this.$confirm('确认退出吗？', '提示', {}).then(() => {
        window.location.href = '/'
      }).catch(() => {})
    },
  }
}
</script>

<style scoped>

</style>
